<template>
	<view>
		<!-- <uni-segmented-control :current="state" :values="items" @clickItem="onClickItem" styleType="text"
			activeColor="#00aaff"></uni-segmented-control> -->
		<view>
			用户所有售后订单
		</view>
		<view v-for="shouhou in shouhouList">

			<uni-card :title="'订单号：'+shouhou.orderId">
				
					<uni-row>
						<uni-col :span="10" style="margin-top: 30rpx;">
							<font style="font-size: 30rpx; font-weight: bold;">
								售后状态:{{shouhouStatus(shouhou.shStatus)}}</font>
						</uni-col>
						<uni-col :span="8">
							<image :src="shouhou.productImg" style="width: 200rpx;height: 200rpx;"></image>
						</uni-col>

						<uni-col :span="10" style="margin-top: 30rpx;">
							<font style="font-size: 30rpx; font-weight: bold;">{{shouhou.productName}}</font>
						</uni-col>
						<uni-col :span="6" style="margin-top: 30rpx;">
							<font style="font-size: 30rpx; float: right;">￥{{shouhou.productPrice}}</font>
							<br>
							<font style="float: right;">×{{shouhou.buyNum}}</font>
						</uni-col>
					</uni-row>
					<uni-row>
						<uni-col :span="24">
							<view>订单总付款：￥{{shouhou.actualAmount}}</view>
							<view style="float: right;">
								<button v-if="shouhou.shStatus==1 || shouhou.shStatus==3"
									@click="quxiaoShouhou(shouhou)"
									style="width: 160rpx;border-radius: 20px;float: right" size="mini">
									取消售后</button>

								<button v-if="shouhou.shStatus==3" @click="fahuo(shouhou)"
									style="width: 160rpx;border-radius: 20px;float: right" size="mini">
									发货</button>

							</view>
						</uni-col>
					</uni-row>
				
			</uni-card>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:"",
				shouhouList: [{
						zyOrder: {
							id: "",
							userId: ""
						},
						zyShouhou: {
							id: ""
						},
						orderDetails: {},
						zyShouhoudetail: {}
					},
					{
						zyOrder: {
							id: "",
							userId: ""
						},
						zyShouhou: {
							id: ""
						},
						orderDetails: {},
						zyShouhoudetail: {}
					}
				],
				items: ['全部', '待付款', '待发货', '已发货', '已完成'],
				type: 'center',
				msgType: 'success',
				messageText: '这是一条成功提示',
				value: ''

			}
		},
		methods: {
			shouhouStatus(val) {
				// 1已申请、2已关闭、3待退货、4已退货、5待退款、6已完成
				if (val == 1) {
					return "已申请";
				} else if (val == 2) {
					return "已关闭";
				} else if (val == 3) {
					return "待退货";
				} else if (val == 4) {
					return "已退货";
				} else if (val == 5) {
					return "待退款";
				} else if (val == 6) {
					return "已完成";
				}
			},

			//id为售后表id，传到后端判断状态为1.已申请或者3.带退货时，状态直接改成2.已关闭
			quxiaoShouhou(shouhou) {
				// 取消售后时，一个订单的所有商品都会取消售后
				console.log(shouhou);
				var id = shouhou.id;
				uni.showModal({
					title: '提示',
					content: '是否确定取消售后',
					success: function(res) {
						if (res.confirm) {
							uni.request({
								url: 'api/order-server/shouhou/quxiaoShouhou',
								header: {
									"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ6eU1hbmFnZSI6eyJpZCI6IjE4MjA3NzkzMTgxODg1NzY3NjgiLCJtYW5hZ2VBY2NvdW50IjoiY2oiLCJtYW5hZ2VOaWNrTmFtZSI6ImNqIn19.AI1W3jxpA1T1k438YI8weWTw_51jKU2uUQAjKKJ3Rig"
								},
								method: "POST",
								data: {
									id,
								},
								success: (res) => {
									if (res.data.code == 200) {
										console.log("取消售后" + res.data);
										uni.showToast({
											title: '取消成功',
											icon: 'success',
											duration: 2000
										});
										//debugger
										//queryAllShouhouOrder();
										


									}

								}
							});

						} else if (res.cancel) {

						}

					}
				});

			},
			fahuo(shouhou) {
				console.log(shouhou);
				this.id = shouhou.id;
				//id为售后表id，传到后端判断状态为1.已申请或者3.带退货时，状态直接改成2.已关闭
				uni.request({
					url: 'api/order-server/shouhou/fahuo',
					header: {
						"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ6eU1hbmFnZSI6eyJpZCI6IjE4MjA3NzkzMTgxODg1NzY3NjgiLCJtYW5hZ2VBY2NvdW50IjoiY2oiLCJtYW5hZ2VOaWNrTmFtZSI6ImNqIn19.AI1W3jxpA1T1k438YI8weWTw_51jKU2uUQAjKKJ3Rig"
					},
					method: "POST",
					data: 
						shouhou,
					
					success: (res) => {
						if (res.data.code == 200) {
							console.log("顾客发货" + res.data);
							uni.showToast({
								title: '发货成功',
								icon: 'success',
								duration: 2000
							});
						}
						this.queryAllShouhouOrder();
					}
				})
			},
			queryAllShouhouOrder() {
	
					//debugger
				//查询所有申请过的售后订单
				uni.request({
					
					url: 'api/order-server/shouhou/queryAllShouhouOrder',
					method: 'POST',
					header: {
						"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ6eU1hbmFnZSI6eyJpZCI6IjE4MjA3NzkzMTgxODg1NzY3NjgiLCJtYW5hZ2VBY2NvdW50IjoiY2oiLCJtYW5hZ2VOaWNrTmFtZSI6ImNqIn19.AI1W3jxpA1T1k438YI8weWTw_51jKU2uUQAjKKJ3Rig"
					},
					success: (res) => {
						//debugger
						if (res.data.code == 200) {
							console.log(res.data);
							this.shouhouList = res.data.data;
						}
					}
				})
			}
		},
		onLoad() {
			this.queryAllShouhouOrder();
		}
	}
</script>

<style>

</style>